/**
 * 系统和道具相关API
 */
import { get, post } from './request'

// 系统相关
// 获取公告
export function getNotice() {
  return post('/system/get_notice')
}

// CDK兑换
export function redeemCdk(code) {
  return post('/system/cdk_reward', {
    code
  })
}

// 获取游戏配置
export function getGameConfig() {
  return post('/system/get_game_config_data')
}

// 获取服务器列表
export function getServerList() {
  return post('/system/server_list')
}

// 获取跑马灯内容
export function getMarquee() {
  return post('/admin/get_pmd')
}

// 道具相关
// 获取背包信息
export function getItemInfo() {
  return post('/item/info')
}

// 使用道具
export function useItem(itemId, count = 1) {
  return post('/item/use_item', {
    id: itemId,
    count
  })
}

// 出售道具
export function sellItem(itemId, count = 1) {
  return post('/item/sell', {
    id: itemId,
    count
  })
}

// 合成道具
export function composeItem(recipeId, count = 1) {
  return post('/item/compose', {
    recipe_id: recipeId,
    count
  })
}

// 商店相关
// 获取商店列表
export function getShopList(shopType = 'general') {
  return post('/shop/list', {
    shop_type: shopType // general, sect, arena, etc.
  })
}

// 购买商品
export function buyShopItem(itemId, count = 1) {
  return post('/shop/buy', {
    item_id: itemId,
    count
  })
}

// 刷新商店
export function refreshShop(shopType = 'general') {
  return post('/shop/refresh', {
    shop_type: shopType
  })
}

// 邮件相关
// 获取邮件列表
export function getMailList() {
  return post('/mail/list')
}

// 读取邮件
export function readMail(mailId) {
  return post('/mail/read', {
    mail_id: mailId
  })
}

// 领取邮件附件
export function claimMailAttachment(mailId) {
  return post('/mail/claim', {
    mail_id: mailId
  })
}

// 删除邮件
export function deleteMail(mailId) {
  return post('/mail/delete', {
    mail_id: mailId
  })
}

// 一键领取所有邮件
export function claimAllMail() {
  return post('/mail/claim_all')
}

// 好友相关
// 获取好友列表
export function getFriendList() {
  return post('/system/friend/list')
}

// 添加好友
export function addFriend(friendId) {
  return post('/system/friend/add', {
    friend_id: friendId
  })
}

// 删除好友
export function deleteFriend(friendId) {
  return post('/system/friend/delete', {
    friend_id: friendId
  })
}

// 经验修炼相关
// 获取经验修炼数据
export function getExpCultivation() {
  return post('/system/cultivation/exp')
}

// 升级经验修炼进度条
export function upgradeExpCultivation(index) {
  return post('/system/cultivation/exp_upgrade', {
    index // 0-3，表示4个进度条中的哪一个
  })
}

// 内功修炼相关
// 获取内功修炼数据
export function getInternalCultivation() {
  return post('/system/cultivation/internal')
}

// 升级内功修炼进度条
export function upgradeInternalCultivation(index) {
  return post('/system/cultivation/internal_upgrade', {
    index // 0-3，表示4个进度条中的哪一个
  })
}

export default {
  getNotice,
  redeemCdk,
  getGameConfig,
  getServerList,
  getMarquee,
  getItemInfo,
  useItem,
  sellItem,
  composeItem,
  getShopList,
  buyShopItem,
  refreshShop,
  getMailList,
  readMail,
  claimMailAttachment,
  deleteMail,
  claimAllMail,
  getFriendList,
  addFriend,
  deleteFriend,
  getExpCultivation,
  upgradeExpCultivation,
  getInternalCultivation,
  upgradeInternalCultivation
}